package com.mc.music_web.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mc.music_web.entity.Singer;
import com.mc.music_web.mapper.SingerMapper;
import com.mc.music_web.services.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class SingerServiceImpl implements SingerService {
    @Autowired
    private SingerMapper singerMapper;


    public int delteSinger(Integer singerId) {
        return singerMapper.delteSinger(singerId);
    }

    public int insert(Singer singer) {
        return singerMapper.insert(singer);
    }

    public List<Singer> selectAllListSinger() {
        return singerMapper.selectAllListSinger();
    }

    public int updateByPrimaryKeySinger(Singer singer) {
        return singerMapper.updateByPrimaryKeySinger(singer);
    }

    public Singer selectByPrimaryKeySinger(Integer singerId) {
        return singerMapper.selectByPrimaryKeySinger(singerId);
    }


    public List<Singer> selectByChooseSinger(String keyword) {
        return singerMapper.selectByChooseSinger(keyword);
    }

    public PageInfo selectSingerLimit(int pageNum) {
        PageHelper.startPage(pageNum,3);
        List<Singer> list = singerMapper.selectAllListSinger();
        PageInfo<Singer> pageInfos = new PageInfo<Singer>(list);
        System.out.println("当前页码："+pageInfos.getPageNum());
        System.out.println("页面大小："+pageInfos.getPageSize());
        System.out.println("总记录数："+pageInfos.getTotal());
        System.out.println("是否有上一页："+pageInfos.isHasPreviousPage());
        System.out.println("是否有下一页："+pageInfos.isHasNextPage());
        System.out.println("总页面数："+pageInfos.getPages());
        return pageInfos;
    }
}
